package com.wj.algorithm.lintcode.string;

public class P55 {
    
    public int charToInt(char ch) {
        return ch;
    }
    public int[] createArrFromString(String A) {
        int[] rs = new int[100];
        for(int i = 0, len = A.length(); i < len; i ++) {
            rs[charToInt(A.charAt(i))] ++;
        }
        return rs;
    }
    public boolean compareStrings(String A, String B) { 
        
        int[] a = createArrFromString(A);
        
        for(int i = 0, len = B.length(); i < len; i ++) {
            int index = charToInt(B.charAt(i));
            if(a[index] < 1) {
                return false;
            }
            a[index] --;
        }
        
        return true;
    }
    
    private static String pow(String s, int time) {
        StringBuilder sb = new StringBuilder();
        while(time -- > 0) {
            sb.append(s);
        }
        return sb.toString();
    }
    
    public static void main(String[] args) {
        P55 p = new P55();
        String a = "ABCDFSADFASFASFASGASFDASGSADFASFRASDFASFDASDF";
        String b = "ACDASDFASBF";
        
        a = pow(a, 10000000);
        b = pow(b, 10000000);
        
        System.out.println("a.length : " + a.length());
        System.out.println("b.length : " + b.length());
        
        long begin = System.currentTimeMillis();
        boolean rs = p.compareStrings(a, b);
        System.out.println(System.currentTimeMillis() - begin);
        System.out.println(rs);
//        System.out.println(p.compareStrings("ABCD", "AABC"));
        
    }
}
